/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upf.grupof.projectphotos.messagesys;

import edu.upf.grupof.projectphotos.messageobj.UserContent;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.filetransfer.FileTransferManager;
import org.jivesoftware.smackx.filetransfer.FileTransferNegotiator;
import org.jivesoftware.smackx.filetransfer.OutgoingFileTransfer;

/**
 *
 * @author fredi
 */
public class ThreadS extends Thread {
    private UserContent uc;
    private Message msg;
    private InstantMessage im;
    
    public ThreadS(UserContent uc, Message msg, InstantMessage im){
        this.uc=uc;
        this.msg=msg;
        this.im=im;
    }
    
    public void run(){
        FileTransferManager manager = new FileTransferManager(im.getCon());
        FileTransferNegotiator.setServiceEnabled(im.getCon(), true);

        OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(msg.getFrom());
        try {
            transfer.sendFile(new File(uc.getPath()), uc.getName());
        } catch (XMPPException ex) {
            Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
